package dyyx;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class HelloProxyMain {

	public static void main(String[] args) {

		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(Hello.class);
		enhancer.setCallback(new MethodInterceptorImpl());
		Hello hello = (Hello) enhancer.create();
		hello.sayHello("dyyx");
		
		System.out.println(hello.toString());

	}

	private static class MethodInterceptorImpl implements MethodInterceptor {
		public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
			System.out.println(method + " run before ");
		    Object result = proxy.invokeSuper(obj, args);	
			System.out.println(method + " run after ,result="+result);
			return result;
		}
	}

}
